package org.puppet.demo.tank.puppet;

import org.puppet.game.World;
import org.puppet.game.base.PuppetUtils;
import org.puppet.game.element.Animation;
import org.puppet.game.element.Puppet;

import android.content.Resources;
import android.graphics.Bitmap;

public class Tank extends Puppet {

	private static int ANI_NUM = 4;
	private static int ANI_STAND_LEFT = 0;
	private static int ANI_STAND_RIGHT = 1;
	private static int ANI_WALK_LEFT = 2;
	private static int ANI_WALK_RIGHT = 3;

	private boolean isJumping = false;
	private boolean isWalking = false;
	private boolean isFaceLeft = false;

	public Tank() {
////		super(ANI_NUM);
////		Resources res = World.current.getResources();
////
////		Bitmap myImage = PuppetUtils.createBitmap(res, R.drawable.mario);
////		Bitmap standRFrame = PuppetUtils.createBitmap(myImage, 0, 0, 25, 30);
////
////		Bitmap standLFrame = PuppetUtils.mirrorBitmap(standRFrame);// PuppetUtils.createBitmap(res,
////																	// R.drawable.playermr1);
////
////		Animation standL = new Animation();
////		standL.addFrame(standLFrame, 1000);
////		standL.setAllFrameCoreXY(12, 29);
////
////		Animation standR = new Animation();
////		standR.addFrame(standRFrame, 1000);
////		standR.setAllFrameCoreXY(12, 29);
////
////		Animation waltL = new Animation();
////		waltL.addFrame(PuppetUtils.createBitmap(res, R.drawable.playerml2), 50);
////		waltL.addFrame(PuppetUtils.createBitmap(res, R.drawable.playerml3), 50);
////		waltL.addFrame(standLFrame, 50);
////		waltL.setAllFrameCoreXY(12, 29);
////
////		Animation waltR = new Animation();
////		waltR.addFrame(PuppetUtils.createBitmap(res, R.drawable.playermr2), 50);
////		waltR.addFrame(PuppetUtils.createBitmap(res, R.drawable.playermr3), 50);
////		waltR.addFrame(standRFrame, 50);
////		waltR.setAllFrameCoreXY(12, 29);
//
//		this.setAnimation(ANI_STAND_LEFT, standL);
//		this.setAnimation(ANI_STAND_RIGHT, standR);
//		this.setAnimation(ANI_WALK_LEFT, waltL);
//		this.setAnimation(ANI_WALK_RIGHT, waltR);

//		changeAnimation(ANI_STAND_RIGHT);
	}

	@Override
	protected void initDirector() {
		super.initDirector();
	}

	public void stand() {
		this.vX = 0;
		this.vY = 0;
		this.acceY = 0;
		this.acceX = 0;
		isWalking = false;
		isJumping = false;
		changeAnimation(isFaceLeft ? ANI_STAND_LEFT : ANI_STAND_RIGHT);
	}

	public void walk(float vX, float vY) {
		this.vX = vX;
		this.vY = vY;
		isFaceLeft = vX == 0 ? isFaceLeft : (vX < 0);
		isWalking = true;
		isJumping = false;
		changeAnimation(isFaceLeft ? ANI_WALK_LEFT : ANI_WALK_RIGHT);
	}

	public void jump(float vX, float vY) {
		this.vX = vX;
		this.vY = vY;
		isFaceLeft = vX == 0 ? isFaceLeft : (vX < 0);
		isWalking = false;
		isJumping = true;
		changeAnimation(isFaceLeft ? ANI_WALK_LEFT : ANI_WALK_RIGHT);
	}

	public boolean isWalking() {
		return isWalking;
	}

	public void setWalking(boolean isWalking) {
		this.isWalking = isWalking;
	}

	public boolean isJumping() {
		return isJumping;
	}

	public void setJumping(boolean isJumping) {
		this.isJumping = isJumping;
	}

}
